package com.example.basic.web.controller.zoneChannel;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.zoneChannel.ZoneChannel;
import com.example.basic.web.service.zoneChannel.ZoneChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Api(value  = "通道管理", tags = {"通道管理"})
@RestController
@RequestMapping("/api/v1/byg/zoneChannel")
public class ZoneChannelController {

    @Resource
    private ZoneChannelService zoneChannelService;

    @Log(title = "通道管理", description = "新增或修改")
    @ApiOperation(value = "新增或修改", notes = "新增或修改")
    @PostMapping("/addOrUpdate")
    public Result<ZoneChannel> addOrUpdate(@ApiParam(name = "zoneChannel", value = "模型", required = true) @RequestBody ZoneChannel zoneChannel) {
        return ResultGenerator.genSuccessResult(zoneChannelService.addOrUpdate(zoneChannel));
    }

    @Log(title = "通道管理", description = "详情")
    @ApiOperation(value = "详情", notes = "详情")
    @PostMapping("/detail")
    public Result<ZoneChannel> detail(@ApiParam(name = "channelCode", value = "通道编码") @RequestParam String channelCode) {
        return ResultGenerator.genSuccessResult(zoneChannelService.detail(channelCode));
    }

    @Log(title = "通道管理", description = "删除")
    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/delete")
    public Result<Integer> delete(@ApiParam(name = "channelCode", value = "通道编码") @RequestParam String channelCode ) {
        return ResultGenerator.genSuccessResult(zoneChannelService.delete(channelCode));
    }

    @Log(title = "通道管理", description = "启用/禁用")
    @ApiOperation(value = "启用/禁用", notes = "启用/禁用")
    @PostMapping("/enableOrDisable")
    public Result<Integer> enableOrDisable(@ApiParam(name = "channelCode", value = "通道编码") @RequestParam String channelCode) {
        return ResultGenerator.genSuccessResult(zoneChannelService.enableOrDisable(channelCode));
    }

    @Log(title = "通道管理", description = "列表")
    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/queryList")
    public Result<IPage<ZoneChannel>> queryList(
            @ApiParam(name = "pharmCode", value = "仓库编码") @RequestParam(required = false) String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码") @RequestParam(required = false) String zoneCode,
            @ApiParam(name = "searchParam", value = "模糊搜索(拼音码,五笔码,名称,编码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "isAll", value = "是否查询全部 0-否，1-是") @RequestParam(defaultValue = "0") String isAll,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<ZoneChannel> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(zoneChannelService.queryList(queryPage,searchParam, isAll,pharmCode,zoneCode));
    }
}
